<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>餐桌列表-订餐管理系统</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../static/css/font.css">
		<link rel="stylesheet" href="../../static/css/weadmin.css">
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
	      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
	      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
	    <![endif]-->
	</head>

	<body>
		<div class="weadmin-nav">
			<span class="layui-breadcrumb">
        <a href="">首页</a>
        <a>
          <cite>餐桌管理</cite></a>
      </span>
			<a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
				<i class="layui-icon" style="line-height:30px">&#x1002;</i></a>
		</div>
		<div class="weadmin-body">
			<div class="weadmin-block">
				<button class="layui-btn" onclick="WeAdminShow('添加餐桌','./add.html',600,400)"><i class="layui-icon"></i>添加</button>
			</div>
			<table class="layui-table" >
				<thead>
					<tr>
						<th>
							<div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
						</th>
						<th>编号</th>
						<th>桌名</th>
						<th>状态</th>
						<th>预定时间</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody id="boardList">
					<tr data-id="1">
						<td>
							<div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id="1"><i class="layui-icon">&#xe605;</i></div>
						</td>
						<td>1</td>
						<td>纽约</td>
						<td>空闲</td>
						<td></td>
						<td class="td-manage">
							<input type="button" value="预定" name="status">
							<a title="删除" onclick="member_del(this,'要删除的id')" href="javascript:;">
								<i class="layui-icon">&#xe640;</i>
							</a>
						</td>
					</tr>
				</tbody>
			</table>
			<div class="page">
				<div>
					<a class="prev" href="">&lt;&lt;</a>
					<a class="num" href="">1</a>
					<span class="current">2</span>
					<a class="num" href="">3</a>
					<a class="num" href="">489</a>
					<a class="next" href="">&gt;&gt;</a>
				</div>
			</div>
		</div>
		<script src="../../static/js/jquery.js"></script>
		<script src="../../static/js/setAjax.js"></script>
		<script src="../../lib/layui/layui.js" charset="utf-8"></script>
		<script src="../../static/js/eleDel.js" type="text/javascript" charset="utf-8"></script>
	</body>
<script>
	layui.use(['form', 'layer'], function() {
		var layer = layui.layer;
		$.ajax({
			url:'/board',
			type:'get',
			dataType:'json',
			success:function (data) {
				layer.msg(data.message,{icon:1,time:2000});
				if(data.state=="success"){
					var _html = '';
					var state="";
					for (var i = 1;i<=data.boardList.length;i++) {
						if(!data.boardList[i-1].boardTime){
							data.boardList[i-1].boardTime="";
						}
						if (data.boardList[i-1].boardStatus=="预定"){
							state="空闲";
						} else {
							state="预定";
						}
						_html+=`<tr data-id=${i}><td><div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id=${i}><i class="layui-icon">&#xe605;</i></div></td><td>${i}</td><td>${data.boardList[i-1].boardName}</td><td>${data.boardList[i-1].boardStatus}</td><td>${data.boardList[i-1].boardTime}</td><td class="td-manage"><input class="layui-btn" type="button" onclick="operate(${data.boardList[i-1].boardId},'${state}')" value=${state} name="status"><input type="button" onclick="deleteBoard(${data.boardList[i-1].boardId})" class="layui-btn layui-btn-danger" value="删除"></td></tr>`;
					}
					$("#boardList").html(_html);
				}else {
					layer.msg(data.message,{icon:2,time:2000})
				}
			},
			error:function () {
				console.log("出错了")
			}
		});
	});
	function operate(boardId,boardStatus) {
		console.log(boardId);
		layui.use(['layer'], function() {
			var layer = layui.layer;
			$.ajax({
				type:'post',
				url:'/board',
				dataType:'json',
				data:{
					_method:'put',
					'boardId':boardId,
					'boardStatus':boardStatus
				},
				success:function (data) {
					if (data.state=="success"){
						layer.msg(data.message,{icon:1,time:2000},function () {
							location.reload();
						});
					}else {
						layer.msg(data.message,{icon:2,time:2000})
					}
				},
				error:function () {
					console.log("出错了")
				}
			})
		})
	}
	function deleteBoard(id) {
		layui.use(['layer'], function() {
			var layer = layui.layer;
			layer.confirm('确认要删除吗？', function(index) {
				//发异步删除数据
				$.ajax({
					url:'/board',
					type:'post',
					dataType:'json',
					data:{
						_method:'delete',
						'boardId':id
					},
					success:function (data) {
						if (data.state=="success"){
							layer.msg(data.message,{icon:1,time:2000},function () {
								location.reload();
							})
						}else {
							layer.msg(data.message,{icon:2,time:2000})
						}
					}
				})
			});
		});
	}
</script>
</html>